import router from './router'
import store from './store'
<<<<<<< HEAD
router.beforeEach((to, from, next) => {
  const token = store.state.user.token
=======
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
NProgress.configure({ showSpinner: false }) // NProgress Configuration
router.beforeEach(async(to, from, next) => {
  const token = store.state.user.token
  NProgress.start()

>>>>>>> a65ad1838d1975b3ee62005f8061eb6c31417121
  if (token) {
    if (to.path === '/login') {
      next('/')
    } else {
<<<<<<< HEAD
      store.dispatch('user/getuserinfo')
=======
      await store.dispatch('user/getuserinfo')
>>>>>>> a65ad1838d1975b3ee62005f8061eb6c31417121
      next()
    }
  } else {
    if (to.path === '/login') {
      next()
    } else {
      next('/login')
    }
  }
})
// import router from './router'
// import store from './store'
// // 白名单中的页面
// const whiteList = ['/login','404']
// router.beforeEach((to,from,next)=>{
//   const token=  store.state.user.token
//   console.log(token);
//   if(token){
//     // 是否有token
//     if(to.path === '/login'){
//       next('/') //到主页
//       console.log('你已经登陆 不能访问登陆页')
//     }else{
//       next()
//     }
//   }else{
//     // 是否有白名单
//     if(whiteList.includes(to.path)){
//       next()
//     }else{
//       next('/login')
//     }
//   }

// })
